package com.wisdytech.linkdcs.equipLifeCycle.malfunction.service.impl;

import com.wisdytech.linkdcs.equipLifeCycle.malfunction.model.MalfunctionDemo;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.github.pagehelper.PageInfo;
import com.wisdytech.common.bean.Filter;
import com.wisdytech.common.bean.StandardResult;
import com.wisdytech.common.constants.CommonConstants;
import com.wisdytech.common.exception.ServiceException;
import com.wisdytech.common.handler.BaseService;
import com.wisdytech.common.utils.BaseUtil;
import com.wisdytech.linkdcs.equipLifeCycle.malfunction.dao.MalfunctionDemoDao;
import com.wisdytech.linkdcs.equipLifeCycle.malfunction.service.IMalfunctionDemoService;
import com.wisdytech.linkdcs.equipStop.dao.EquipStopDao;
import com.wisdytech.linkdcs.equipStop.model.EquipStop;
import com.wisdytech.linkdcs.system.dao.ISysDictDao;
import com.wisdytech.linkdcs.system.model.SysDict;
import com.wisdytech.linkdcs.system.model.SysUser;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author chenbin
 * @since 2018-07-24
 */
@Service("iMalfunctionDemoService")
@Transactional
public class MalfunctionDemoServiceImpl extends BaseService<MalfunctionDemoDao, MalfunctionDemo> implements IMalfunctionDemoService {

	@Resource
	private ISysDictDao iSysDictDao;
	
	@Resource
	private MalfunctionDemoDao malfunctionDemoDao;
	@Override
	public List<SysDict> listMalfunctionReasonBySearch(String search) {
		EntityWrapper<SysDict> ew = new EntityWrapper<>();
		ew.eq("PARENT_KEY", "STOP_REASON");
		if(search!=null && search!="") {
			ew.like("DICT_VALUE", search);
		}
		return iSysDictDao.selectList(ew);
	}
	@Override
	public void addDemo(MalfunctionDemo malfunctionDemo, String loginName) {
		malfunctionDemo.setPkId(BaseUtil.getUUID());
		malfunctionDemo.setDelFlag(CommonConstants.DEL_FLAG);
		int num = malfunctionDemoDao.insert(malfunctionDemo);
		
	}
	@Override
	public PageInfo<MalfunctionDemo> listDemoByFilter(String malfunctionType, String malfunctionTitle, Filter filter) {
		List<MalfunctionDemo> list = super.beforeList(MalfunctionDemoDao.class, filter)
                .listDemoByFilter(malfunctionType,malfunctionTitle);
        PageInfo<MalfunctionDemo> page = new PageInfo<>(list);
        return page;
	}
	@Override
	public MalfunctionDemo getDemoById(String pkId) {
		return malfunctionDemoDao.getDemoById(pkId);
	}
	@Override
	public void updateDemo(MalfunctionDemo malfunctionDemo, String loginName) {
		malfunctionDemoDao.updateById(malfunctionDemo);
		
	}
	@Override
	public void delDemoById(String pkIds) {
        List<String> idList = new ArrayList<String>();
        String[] id = pkIds.split(",");
        for (int i = 0; i < id.length; i++) {
            idList.add(id[i]);
        }
        malfunctionDemoDao.deleteBatchIds(idList);
		
	}
	@Override
	public List<MalfunctionDemo> selectDemoByTitle(String search) {
		EntityWrapper<MalfunctionDemo> ew = new EntityWrapper<>();
		if(search!=null && search!="") {
			ew.like("MALFUNCTION_TITLE", search);
		}
		ew.eq("DEL_FLAG", CommonConstants.DEL_FLAG);		
		return malfunctionDemoDao.selectList(ew);
	}

	

}
